var i;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var Item_Shop_GoldItem_UIBindings = require("AA_Item_Shop_GoldItem_UIBindings");
var ResKeeper = require("AA_ResKeeper");
var Excel = require("AA_Excel");
var HallManager = require("AA_HallManager");
var PlayerDataManager = require("AA_PlayerDataManager");
var TipsManager = require("AA_TipsManager");
var Const_Hall = require("AA_Const_Hall");
var UIManager = require("AA_UIManager");
var BundleConfig = require("AA_BundleConfig");
var UIConfig_Home = require("AA_UIConfig_Home");
var ADManager = require("AA_ADManager");
var EventManager = require("AA_EventManager");
var EvenType = require("AA_EvenType");
var RedPointControl = require("AA_RedPointControl");
var HallGlobalVariable = require("AA_HallGlobalVariable");
var CommonUtils = require("AA_CommonUtils");
var Const_Common = require("AA_Const_Common");
var _decorator = cc._decorator;
var _ccclass = _decorator.ccclass;
var _property = _decorator.property;

var _def_Item_Shop_GoldItem = function (e) {
  function _creator() {
    var t = null !== e && e.apply(this, arguments) || this;
    t.auto_ui = null;
    t.isStart = true;
    t.childIndex = 0;
    t.addCount = 0;
    t.priceNum = 0;
    return t;
  }
  __extends(_creator, e);
  _creator.prototype.StartSet = function (e) {
    var t = this.node.getChildByName("redPoint");
    t && (t.active = 0 == e);
    var o = Excel.Excel.shopControl(1);
    if (this.isStart) {
      this.isStart = false;
      this.childIndex = e;
      switch (e) {
        case 0:
          this.auto_ui.txt_nameLabel.string = "一点金币";
          this.auto_ui.txt_countLabel.string = "X" + o.gold1Count;
          this.addCount = o.gold1Count;
          break;
        case 1:
          this.auto_ui.txt_nameLabel.string = "一袋金币";
          this.auto_ui.txt_countLabel.string = "X" + o.gold2Count;
          this.auto_ui.txt_priceLabel.string = "" + o.gold2Price;
          this.auto_ui.node_diamondIcon.active = true;
          this.addCount = o.gold2Count;
          this.priceNum = o.gold2Price;
          break;
        case 2:
          this.auto_ui.txt_nameLabel.string = "一箱金币";
          this.auto_ui.txt_countLabel.string = "X" + o.gold3Count;
          this.auto_ui.txt_priceLabel.string = "" + o.gold3Price;
          this.auto_ui.node_diamondIcon.active = true;
          this.addCount = o.gold3Count;
          this.priceNum = o.gold3Price;
      }
    }
    if (0 == e) {
      this.auto_ui.btn_buyBtn.interactable = true;
      if (0 == HallManager.HallMgr.shopData.videoBuyGoldCount) {
        this.auto_ui.txt_priceLabel.string = "免费";
        this.auto_ui.node_videoIcon.active = false;
      } else {
        var n = o.gold1Time - HallManager.HallMgr.shopData.videoBuyGoldCount + 1;
        if (n <= 0) {
          this.auto_ui.txt_priceLabel.string = "已售罄";
          this.auto_ui.node_videoIcon.active = false;
          this.auto_ui.btn_buyBtn.interactable = false;
        } else {
          this.auto_ui.txt_priceLabel.string = "免费(" + n + ")";
          this.auto_ui.node_videoIcon.active = true;
        }
      }
    }
  };
  _creator.prototype.onLoad = function () {
    this.auto_ui.addClickListener(this._clickListener, this);
  };
  _creator.prototype._clickListener = function (e) {
    switch (e) {
      case this.auto_ui.btn_buyBtn:
        this.BuyThis();
    }
  };
  _creator.prototype.BuyThis = function () {
    var e = this;
    if (0 == this.childIndex) {
      if (0 == Excel.Excel.shopControl(1).gold1Time - HallManager.HallMgr.shopData.videoBuyGoldCount + 1) {
        return void TipsManager.TipMgr.showToast("已售罄");
      }
      if (0 == HallManager.HallMgr.shopData.videoBuyGoldCount) {
        this.VideoBuyCount();
      } else {
        ADManager.ADMgr.showRewardedVideo("商城视频购买金币", function () {
          e.VideoBuyCount();
        });
      }
    } else {
      var t = this;
      var o = new Const_Hall.ShopItemInfoData();
      o.iconSpriteFrame = this.auto_ui.sp_iconSprite.spriteFrame;
      o.qualitySpriteFrame = null;
      o.titleName = this.auto_ui.txt_nameLabel.string;
      o.count = this.addCount;
      o.richType = Const_Hall.RichType.钻石;
      o.price = this.priceNum;
      o.infoStr = "金币可用于装备升级，可通过主线关卡获得";
      o.clickCallBack = function () {
        if (PlayerDataManager.PlayerDataMgr.SubDiamond(t.priceNum)) {
          CommonUtils.default.SendPoint(Const_Common.SendPointType.外围打点, "钻石购买" + t.addCount + "金币");
          t.ShowGetReward(t.addCount, function () {
            PlayerDataManager.PlayerDataMgr.AddGold(t.addCount);
            TipsManager.TipMgr.showToast("购买成功，获得金币" + t.addCount);
          });
        }
      };
      UIManager.default.open(BundleConfig.BundleNames.Home, UIConfig_Home.UIView_Home.UI_ShopItemInfo, o);
    }
  };
  _creator.prototype.VideoBuyCount = function () {
    var e = this;
    this.ShowGetReward(e.addCount, function () {
      PlayerDataManager.PlayerDataMgr.AddGold(e.addCount);
      TipsManager.TipMgr.showToast("购买成功，获得金币" + e.addCount);
      HallManager.HallMgr.shopData.videoBuyGoldCount++;
      1 == HallManager.HallMgr.shopData.videoBuyGoldCount && EventManager.EventMgr.dispatchEvent(EvenType.EVENT_TYPE.MainRedPointChange, RedPointControl.RedPointType.freeGold);
      HallManager.HallMgr.SaveShopData();
      e.StartSet(e.childIndex);
    });
  };
  _creator.prototype.ShowGetReward = function (e, t) {
    var o = new Const_Hall.GetItemsData();
    o.ids = [HallGlobalVariable.default.goldId];
    o.counts = [e];
    o.clickCallBack = t;
    UIManager.default.open(BundleConfig.BundleNames.Home, UIConfig_Home.UIView_Home.UI_GetItems, o);
  };
  __decorate([_property(Item_Shop_GoldItem_UIBindings.default)], _creator.prototype, "auto_ui", undefined);
  return __decorate([_ccclass], _creator);
}(ResKeeper.default);
exports.default = _def_Item_Shop_GoldItem;